<!--
 * @Description: 
 * @Author: ZachGmy
 * @Date: 2022-08-25 15:30:07
 * @LastEditors: HeAo
 * @LastEditTime: 2022-08-25 20:27:32
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <input type="text" name="" id="inp">
  <button onclick="btnClick()">点我呀</button>
  <script>
    // // 防抖
    // var inp = document.getElementById('inp')
    // var timeID = null
    // inp.oninput = function () {
    //   clearTimeout(timeID)
    //   timeID = setTimeout(() => {
    //     console.log(`你输入的值是${this.value}`);
    //   }, 500);
    // }

    // 节流
    var lastTime = null

    function btnClick() {
      var currentTime = Date.now()
      if (currentTime - lastTime >= 3000) {
        console.log('按钮被点击了');
        lastTime = currentTime
      }
    }
  </script>
</body>

</html>